package util;

import java.util.Date;
import java.util.List;

import dataBase.Order;

public class Util {
	private Util() {}
	static private Util ins = new Util();
	static public Util getIns() {
		return ins;
	}
	static public enum Times {DAYS,HOURS,MINUTES}
	
	static public long getTime(Long time, Times type){
		long result = time/60000;
		int mod = 60;
		switch(type){
		case DAYS:
			result/=24;
			mod = 1;
		case HOURS:
			result/=60;
			mod = 24;
			break;
		}

		return result%mod;

	}
	static public long getFirstDelay(List<Order> ordersList,Long[] urgencyTime){
		Date result = null;
		for(Order order : ordersList){
			if(!order.isDelay(urgencyTime, null)){
				Date orderDelayDate = order.getDelayDate(urgencyTime);
				if(orderDelayDate!=null &&(result==null ||  orderDelayDate.before(result)))
					result = orderDelayDate;
			}
				
		}
		if(result==null)
			return 0;
		return result.getTime()-new Date().getTime();
	}
}
